package gdut.imis.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import gdut.imis.Utils.Result;
import gdut.imis.domain.ClassCommittee;
import gdut.imis.enums.Status;
import gdut.imis.mapper.ClassCommitteeMapper;
import gdut.imis.service.ClassCommitteeService;
import gdut.imis.vo.ClassCommitteeVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @Description
 * @Author JiaFu
 * @Date 2023/4/7 14:15
 */
@Service
@RequiredArgsConstructor
public class ClassCommitteeServiceImpl extends ServiceImpl<ClassCommitteeMapper, ClassCommittee> implements ClassCommitteeService {

    private final ClassCommitteeMapper classCommitteeMapper;

    /***
     * 新增班委档案
     * @param: classCommittee
     * @return Result
     */
    @Override
    public Result addClassCommittee(ClassCommittee classCommittee) {
        if (Objects.isNull(classCommittee)) {
            return Result.errorWithArgs(Status.REQUEST_PARAMS_NOT_VALID_ERROR, "classCommittee");
        }
        boolean flag = this.save(classCommittee);
        if (flag) {
            return Result.success();
        }
        return Result.errorWithArgs(Status.FAILED, "新增班委档案失败");
    }

    /***
     * 根据学生id查询学生班委档案回忆录
     * @param: studentId
     * @return Result
     */
    @Override
    public Result getClassCommitteMemoryByStuId(Long studentId) {

        ClassCommitteeVo classCommitteeVo = classCommitteeMapper.getClassCommitteMemoryByStuId(studentId);
        if (Objects.isNull(classCommitteeVo)) {
            return Result.errorWithArgs(Status.FAILED,"没有查询到该学生班委档案回忆录");
        }
        return Result.success(classCommitteeVo);
    }
}
